#include "headers.h"

Model::Model()
{

}

QSqlDatabase Model::ConnectionInit()
{
    // use mysql
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("parkinglot");
    db.setUserName("testuser");
    db.setPassword("123456");
    if(!db.open())
        qDebug() << "fail to connect to root mysql admin";
    else qDebug() << "open success";

    return db;
}

QSqlDatabase Model::ConnectionInit(QString)
{
   QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
   db.setDatabaseName("db_parkid");
   if(!db.open())
       qDebug() << "fail to connect to root mysql admin";
   else qDebug() << "open success";

   return db;
}


bool Model::testConnection()
{
    // show drivers available
    qDebug()<<"Available drivers:";
    QStringList drivers= QSqlDatabase::drivers();

    foreach (QString driver, drivers)
        qDebug() << driver;

    return true;
}
